﻿using UnityEditor;
using UnityEditor.EditorTools;
using UnityEngine;

namespace EditorExtension
{
    [EditorTool("Move Right")]
    public class MoveRightEditorTool : EditorTool
    {
        public override void OnToolGUI(EditorWindow window)
        {
            window.ShowNotification(new GUIContent("Move Right EditorTool"));

            EditorGUI.BeginChangeCheck();
            Vector3 position = Tools.handlePosition;

            // 绘制绿色箭头
            using (new Handles.DrawingScope(Color.green))
            {
                position = Handles.Slider(position, Vector3.right);
            }

            // 如果有拖动，则变更位置
            if (EditorGUI.EndChangeCheck())
            {
                Vector3 delta = position - Tools.handlePosition;
                
                Undo.RecordObjects(Selection.transforms, "Move Right");
                
                foreach (var transform in Selection.transforms)
                {
                    transform.position += delta;
                }
            }
        }
    }
}